Skip to content

fix(tools): restrict CORS origin in Dev UI server#5259

Merged
MichaelDoyle merged 2 commits intogenkit-ai:mainfrom
q1uf3ng:fix/devui-cors-env-leak
May 7, 2026
Merged

fix(tools): restrict CORS origin in Dev UI server#5259
MichaelDoyle merged 2 commits intogenkit-ai:mainfrom
q1uf3ng:fix/devui-cors-env-leak

Conversation

@q1uf3ng
Copy link
Copy Markdown
Contributor

@q1uf3ng q1uf3ng commented May 7, 2026

Summary

The Dev UI server has two security issues:

  1. CORS wildcard (server.ts): Access-Control-Allow-Origin: * is hardcoded, allowing any website to make cross-origin requests and read responses.

  2. Environment variable disclosure (router.ts): getGenkitEnvironment returns every environment variable without filtering, including GOOGLE_API_KEY, GEMINI_API_KEY, and other secrets.

Combined, any website a developer visits while running genkit start can silently read all their API keys via cross-origin fetch.

Fix

  • Restrict CORS origin to http://localhost:{port} (the Dev UI itself)
  • Filter environment variables matching sensitive patterns (KEY, SECRET, PASSWORD, TOKEN, CREDENTIAL, PRIVATE) from the response

Reproduction

genkit start
# From any webpage:
# fetch('http://localhost:4000/api/getGenkitEnvironment').then(r=>r.json()).then(console.log)
# Returns all env vars including GOOGLE_API_KEY

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 7, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces security enhancements by filtering sensitive environment variables from the Dev UI and restricting CORS origins. Feedback suggests expanding the sensitive pattern list to include 'AUTH' and 'SALT' and improving the CORS origin configuration to support '127.0.0.1' and handle potential port assignment issues.

Comment thread genkit-tools/common/src/server/router.ts Outdated
Comment thread genkit-tools/common/src/server/server.ts Outdated
Comment thread genkit-tools/common/src/server/server.ts Outdated
Copy link
Copy Markdown
Contributor

@MichaelDoyle MichaelDoyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

The Dev UI server uses `Access-Control-Allow-Origin: *`, allowing any
website to make cross-origin requests and read responses. This enables
credential theft via CSRF when combined with the getGenkitEnvironment
endpoint.

Restrict CORS to localhost origins using the same regex pattern as the
telemetry server.
@q1uf3ng q1uf3ng force-pushed the fix/devui-cors-env-leak branch from e00a681 to c95d125 Compare May 7, 2026 14:37
@q1uf3ng q1uf3ng changed the title security: restrict CORS and filter sensitive env vars in Dev UI fix(tools): restrict CORS origin in Dev UI server May 7, 2026
Removed comment about localhost origins in CORS configuration.
@MichaelDoyle MichaelDoyle merged commit 988e4eb into genkit-ai:main May 7, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants